package com.gxd.esimport;

import java.sql.*;

/**
 * 关系型库Client工具类
 *
 * @author zxb
 * @version 1.0.0
 *          2016年12月24日 08:12
 * @since Jdk1.6
 */
public class JdbcClientHelper {

    public  static Connection conn;

    /**
     * 获取连接
     *
     * @return
     */
    public static void getConnection()  {

        try {
            // 加载驱动包
            Class.forName("oracle.jdbc.driver.OracleDriver");
            // 用户名、密码// 返回连接
            JdbcClientHelper.conn = DriverManager.getConnection("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.10.150)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=gxd)))", "regis", "gxd*gis*12");
            //JdbcClientHelper.conn = DriverManager.getConnection("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.50.41)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=gxd)))", "regis", "regis");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 释放数据库连接
     *
     * @param connection
     * @param preparedStatement
     * @param resultSet
     */
    public static void releaseConnection(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet) {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                System.out.println("close resultSet error!");
                e.printStackTrace();
            }
        }
        if (preparedStatement != null) {
            try {
                preparedStatement.close();
            } catch (SQLException e) {
                System.out.println("close preparedStatement error!");
                e.printStackTrace();
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                System.out.println("close connection error!");
                e.printStackTrace();
            }
        }
    }

}
